var config = require('../../config');
var whost = config.whost.replace('api', 'boss');
var request = require('../../support').request2;

/**
 * 首页
 * @return promise
 */
exports.promoter = function (context, memberId, projectId) {
  return request(context, {
    url: whost + '/popularize-api/api/json/code/getQrCode',
    data: {
      memberId: memberId,
      projectId: projectId,
    }
  });
};

/**
 * 检查是否注册
 * @return promise
 */
exports.acceptProtocol = function (context, memberId, projectId) {
  return request(context, {
    url: whost + '/popularize-api/api/json/code/isAgreement',
    data: {
      memberId: memberId,
      projectId: projectId,
    }
  });
};

/**
 * 积分详情
 * @return promise
 */
exports.details = function (context, memberId) {
  return request(context, {
    url: whost + '/popularize-api/api/json/integral/getInviterIntegralSum',
    data: {
      inviterMemberId: memberId,
    }
  });
};

/**
 * 发展的用户
 * @return promise
 */
exports.members = function (context, memberId, page, size) {
  return request(context, {
    url: whost + '/popularize-api/api/json/integral/getInvitedIntegralSum',
    data: {
      inviterMemberId: memberId,
      pageNo: page || 1,
      pageSize: size || 20,
    }
  });
};

/**
 * 积分详情
 * @return promise
 */
exports.rewards = function (context, memberId, type, page, size) {
  return request(context, {
    url: whost + '/popularize-api/api/json/integral/getInviterIntegralDetail',
    data: {
      inviterMemberId: memberId,
      integralType: type, // 积分类型　BD:绑定 PC:频次 XD:下单
      pageNo: page || 1,
      pageSize: size || 20,
    }
  });
};

/**
 * 被邀请用户的积分详情
 * @return promise
 */
exports.behavior = function (context, memberId, invitedId, type, page, size) {
  return request(context, {
    url: whost + '/popularize-api/api/json/integral/getInvitedIntegralDetail',
    data: {
      inviterMemberId: memberId,
      invitedMemberId: invitedId,
      integralType: type, // 积分类型　BD:绑定 PC:频次 XD:下单
      pageNo: page || 1,
      pageSize: size || 20,
    }
  });
};